home *** CD-ROM | disk | FTP | other *** search
- package com.sun.java.swing;
-
- import java.awt.AWTEvent;
- import java.awt.Point;
- import java.awt.Rectangle;
- import java.awt.event.InputEvent;
- import java.awt.event.MouseAdapter;
- import java.awt.event.MouseEvent;
- import java.io.IOException;
- import java.io.ObjectInputStream;
- import java.io.ObjectOutputStream;
- import java.io.Serializable;
-
- class Autoscroller extends MouseAdapter implements Serializable {
- transient MouseEvent event;
- transient Timer timer;
- JComponent component;
-
- Autoscroller(JComponent c) {
- if (c == null) {
- throw new IllegalArgumentException("component must be non null");
- } else {
- this.component = c;
- this.timer = new Timer(100, new AutoScrollTimerAction(this));
- this.component.addMouseListener(this);
- }
- }
-
- public void mouseDragged(MouseEvent e) {
- Rectangle visibleRect = this.component.getVisibleRect();
- boolean contains = visibleRect.contains(e.getX(), e.getY());
- if (contains) {
- if (this.timer.isRunning()) {
- this.stop();
- }
- } else {
- Point screenLocation = this.component.getLocationOnScreen();
- this.event = new MouseEvent(this.component, ((AWTEvent)e).getID(), ((InputEvent)e).getWhen(), ((InputEvent)e).getModifiers(), e.getX() + screenLocation.x, e.getY() + screenLocation.y, e.getClickCount(), e.isPopupTrigger());
- if (!this.timer.isRunning()) {
- this.timer.start();
- }
- }
-
- }
-
- public void mouseReleased(MouseEvent e) {
- this.stop();
- }
-
- private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException {
- s.defaultReadObject();
- this.timer = new Timer(100, new AutoScrollTimerAction(this));
- }
-
- void stop() {
- this.timer.stop();
- this.event = null;
- }
-
- private void writeObject(ObjectOutputStream s) throws IOException {
- s.defaultWriteObject();
- }
- }
-